package org.yoao.crm.business.impl;

import java.util.List;
import java.util.Map;

import org.apache.commons.beanutils.BeanUtils;
import org.yoao.crm.bean.Customer;
import org.yoao.crm.bean.CustomerAttributes;
import org.yoao.crm.business.service.ICustomerAttributeService;
import org.yoao.crm.dao.CustomerAttributesDAO;
import org.yoao.crm.dao.CustomerDAO;
import org.yoao.crm.struts.form.CustomerAttributesForm;

/**
 * @author Weishion.Yi
 * @description
 * @date 2010-11-20 下午03:51:28
 */
public class CustomerAttributeServiceImpl implements ICustomerAttributeService {
	private CustomerAttributesDAO customerAttributesDAO = new CustomerAttributesDAO();

	@Override
	public CustomerAttributesForm add(CustomerAttributesForm form)
			throws Exception {
		CustomerAttributes customerAttribute = new CustomerAttributes();
		BeanUtils.copyProperties(customerAttribute, form);
		int result = customerAttributesDAO.insert(customerAttribute);
		if (result > -1){
			form.setId(String.valueOf(result));
			form.setInfo("保存成功.");
		}else
			form.setInfo("保存失败.");
		return form;
	}

	@Override
	public void delete(String id) throws Exception {
		customerAttributesDAO.delete(id);
	}

	@Override
	public CustomerAttributesForm getCustomerAttribute(String id)
			throws Exception {
		CustomerAttributesForm form = new CustomerAttributesForm();
		CustomerAttributes customerAttribute = customerAttributesDAO
				.findById(id);
		BeanUtils.copyProperties(form, customerAttribute);
		return form;
	}

	@Override
	public List getView(String customerId, Map<String, String> map) throws Exception {
		return customerAttributesDAO.findAll(customerId, map);
	}

	@Override
	public CustomerAttributesForm modify(CustomerAttributesForm form)
			throws Exception {
		CustomerAttributes customerAttribute = new CustomerAttributes();
		BeanUtils.copyProperties(customerAttribute, form);
		if (customerAttributesDAO.modify(customerAttribute) > -1)
			form.setInfo("保存成功.");
		else
			form.setInfo("保存失败.");
		return form;
	}

	@Override
	public Customer findCustomerByCode(String customerId) throws Exception {
		return new CustomerDAO().findCustomerById(customerId);
	}

	@Override
	public void sign(String id, String signValue, String signTime)
			throws Exception {
		customerAttributesDAO.sign(id, signValue, signTime, null, null);
	}
}